import Vue from 'vue'
import VueRouter from "vue-router"
import {routerMode} from '@/config/env'

import Index from '@/views/Index'
import login from '@/views/Login'
import User from "@/views/User"
import NotFound from "@/views/NotFound"
import store from '@/store/index'


Vue.use(VueRouter)

let routes = [
  {
    path: '/',
    name: 'index',
    component: Index,
    meta: { requiresAuth: true },
    beforeEnter: function (to, from, next) {  //独享路由守卫
      try {
        document.getElementById('paper').className = 'back_out';
        setTimeout(() => {
          next()
        }, 1500)
      } catch (e) {
        next()
      }
    }
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  //动态路由
  {path: '/user/:id', name: 'user', component: User},
  // 将匹配所有内容并将其放在 `$route.params.pathMatch` 下，404
  {path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound},
/*  {
    path: '/Map',
    name: 'Map',
    component: Map
  },*/

]
const router = new VueRouter({
  mode: routerMode,
  routes
})
//路由守卫
// router.beforeEach((to, from, next) => { // 全局路由守卫
//   if (to.path === '/login')return next();
//   store.state.login?next():next({path:"/login"});
// })
export {router}
